#include "unp.h"

void str_cli(FILE *fp, int sockfd) {
	char sendline[MAXLINE], recvline[MAXLINE];
	while (fgets(sendline, MAXLINE, fp) != NULL) {
		write(sockfd, sendline, strlen(sendline));
		if (readline(sockfd, recvline, MAXLINE) == 0)
			err_quit("str_cli: server terminate prematuurely");
		fputs(recvline, stdout);
	}
}


int main(int argc, char **argv) {
	int sockfd[5];
	struct sockaddr_in servaddr;
	if (argc != 2)
		err_quit("usage: cli <IPaddress>");
	for (int i = 0; i < 5; i++) {
		sockfd[i] = Socket(AF_INET, SOCK_STREAM, 0);
		bzero(&servaddr, sizeof(servaddr));
		servaddr.sin_family = AF_INET;
		servaddr.sin_port = htons(9999);
		Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
		Connect(sockfd[i], (SA*)&servaddr, sizeof(servaddr));
	}
	str_cli(stdin, sockfd[0]);
	exit(0);
}

